package com.upb.webserver.common.enums;

import lombok.Getter;
import lombok.ToString;
import lombok.extern.slf4j.Slf4j;

@Getter
@ToString
@Slf4j
public enum FiscoRemoteNodeTypeEnum {
    CONSENSUS("sealer", "fisco共识节点"),
    OBSERVER("observer", "FISCO观察节点"),
    FREE("remove", "fisco游离节点");


    private String type;
    private String description;

    FiscoRemoteNodeTypeEnum(String type, String description) {
        this.type = type;
        this.description = description;
    }

    /**
     * @param type
     * @return
     */
    public static FiscoRemoteNodeTypeEnum getById(String type) {
        for (FiscoRemoteNodeTypeEnum value : FiscoRemoteNodeTypeEnum.values()) {
            if (value.type.equalsIgnoreCase(type)) {
                return value;
            }
        }
        return null;
    }

    /**
     *
     * @return
     */
    public NodeTypeEnum convertToNodeTypeEnum() {
        switch (this) {
            case CONSENSUS:
                return NodeTypeEnum.FISCO_CONSENSUS;
            case OBSERVER:
                return NodeTypeEnum.FISCO_OBSERVED;
            default:
                return NodeTypeEnum.FISCO_FREE;
        }
    }

}
